/**
 * Created by Administrator on 2025/5/29.
 * */
#include "AINodeInferController.h"
#include <iostream>
#include <thread>

BaseObject *createAINodeInferController() {
    return new AINodeInferController();
}

void destroyAINodeInferController(BaseObject *p) {
    SAFE_DELETE(p);
}

AINodeInferController::AINodeInferController(){
}

AINodeInferController::~AINodeInferController() {
}

/* 如果使用了DDS_Reader或者DDS_Writer，则对应的input或者output前64个字节为DataFormat head首部 */
void AINodeInferController::onCompute(buffer_table_t *input, buffer_table_t *output) {
    std::this_thread::sleep_for(std::chrono::milliseconds(1000));
    // AIPC模块
    if (input->list[1]->valid) {
        int *pAIPCState = reinterpret_cast<int*>(input->list[1]->data);
        if (*pAIPCState > 0) {
            auto aiPCStateHolder = GlobalParameters::shareInstance()->findParameter("aiPCState");
            int *aiPCState = static_cast<int*>(GlobalParameters::shareInstance()->getValue(aiPCStateHolder, dynamic_cast<TaskModule*>(this)));
            *aiPCState = *pAIPCState;
            std::cout << "AINodeInfer::AINodeInferController 接收到AIPC模块模型升级通知：state=" << *pAIPCState << "; !!!!!!!!!!" << std::endl;
        }
    }
    // AICFAR模块
    if (input->list[2]->valid) {
        int *pAICFARState = reinterpret_cast<int*>(input->list[2]->data);
        if (*pAICFARState > 0) {
            auto aiCFARStateHolder = GlobalParameters::shareInstance()->findParameter("aiCFARState");
            int *aiCFARState = static_cast<int*>(GlobalParameters::shareInstance()->getValue(aiCFARStateHolder, dynamic_cast<TaskModule*>(this)));
            *aiCFARState = *pAICFARState;
            std::cout << "AINodeInfer::AINodeInferController 接收到AICFAR模块模型升级通知：state=" << *pAICFARState << "; !!!!!!!!!!" << std::endl;
        }
    }
}
